//// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
//package com.linqingying.gitcode.pullrequest
//
//import com.intellij.collaboration.file.codereview.CodeReviewDiffVirtualFile
//import com.intellij.collaboration.ui.codereview.CodeReviewAdvancedSettings
//import com.intellij.diff.impl.DiffEditorViewer
//import com.intellij.diff.util.DiffUserDataKeysEx
//import com.intellij.openapi.components.service
//import com.intellij.openapi.project.Project
//import com.intellij.vcs.editor.ComplexPathVirtualFileSystem
//import com.linqingying.gitcode.api.GCRepositoryCoordinates
//import com.linqingying.gitcode.i18n.GitCodeBundle
//import com.linqingying.gitcode.pullrequest.data.GCPRDataContextRepository
//import com.linqingying.gitcode.pullrequest.data.GCPRIdentifier
//import com.linqingying.gitcode.pullrequest.ui.diff.GCPRDiffService
//
//internal data class GCPRDiffVirtualFile(private val fileManagerId: String,
//                                        private val project: Project,
//                                        private val repository: GCRepositoryCoordinates,
//                                        private val pullRequest: GCPRIdentifier)
//  : CodeReviewDiffVirtualFile(getFileName(pullRequest)) {
//  override fun getFileSystem(): ComplexPathVirtualFileSystem<*> = GCPRVirtualFileSystem.getInstance()
//
//  override fun getPath(): String = (fileSystem as GCPRVirtualFileSystem)
//    .getPath(fileManagerId, project, repository, pullRequest, true)
//
//  override fun getPresentablePath(): String = getPresentablePath(repository, pullRequest)
//  override fun getPresentableName(): String = GitCodeBundle.message("pull.request.diff.editor.title", pullRequest.number)
//
//  override fun isValid(): Boolean = isFileValid(fileManagerId, project, repository)
//
//  override fun createViewer(project: Project): DiffEditorViewer {
//    val processor = if (CodeReviewAdvancedSettings.isCombinedDiffEnabled()) {
//      project.service<GCPRDiffService>().createCombinedDiffProcessor(repository, pullRequest)
//    }
//    else {
//      project.service<GCPRDiffService>().createDiffRequestProcessor(repository, pullRequest)
//    }
//    processor.context.putUserData(DiffUserDataKeysEx.COMBINED_DIFF_TOGGLE, CodeReviewAdvancedSettings.CodeReviewCombinedDiffToggle)
//    return processor
//  }
//}
//
//private fun isFileValid(fileManagerId: String, project: Project, repository: GCRepositoryCoordinates): Boolean {
//  val dataContext = GCPRDataContextRepository.getInstance(project).findContext(repository) ?: return false
//  return dataContext.filesManager.id == fileManagerId
//}
//
//private fun getPresentablePath(repository: GCRepositoryCoordinates, pullRequest: GCPRIdentifier) =
//  "${repository.toUrl()}/pulls/${pullRequest.number}.diff"
//
//private fun getFileName(pullRequest: GCPRIdentifier): String = "#${pullRequest.number}.diff"
